package com.mfn.airobot.repository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Anyang
 * @version 1.0.0
 * @date 2025/03/25 11:03:36
 * @description
 * @className java.lang.String
 */
@Component
@RequiredArgsConstructor
public class InMemoryChatHistoryRepository implements ChatHistoryRepository{

    private final Map<String, List<String>> chatHistory = new HashMap<>();

    @Override
    public void save(String type, String chatId) {
        List<String> chatIds = chatHistory.computeIfAbsent(type, k -> new ArrayList<>());
        if(!chatIds.contains(chatId)){
            chatIds.add(chatId);
        }
    }

    @Override
    public List<String> getChatIds(String type) {
        return chatHistory.getOrDefault(type, new ArrayList<>());
    }

    @Override
    public void delete(String type, String chatId) {
        List<String> chatIds = chatHistory.getOrDefault(type, new ArrayList<>());
        chatIds.remove(chatId);
    }
}
